﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using NTwitter;
using TwitterClient2.Controller;
using TwitterClient2.Model;

namespace TwitterClient2.Components
{
    public class PanelMessageDetail : Panel
    {
        private Label labelDate;
        private Label labelSender;
        private Label labelDateValue;
        private Label labelSenderValue;
        private Button buttonCancel;
        private Button buttonReply;
        private Label labelMessage;
        private Message message;
        private TwitterClientController controller = TwitterClientController.getInstance();
        private TwitterClientModel model = TwitterClientModel.getInstance();

        public PanelMessageDetail()
        {
            InitializeComponent();
        }
        private void InitializeComponent()
        {
            this.labelDate = new System.Windows.Forms.Label();
            this.labelSender = new System.Windows.Forms.Label();
            this.labelDateValue = new System.Windows.Forms.Label();
            this.labelSenderValue = new System.Windows.Forms.Label();
            this.labelMessage = new System.Windows.Forms.Label();
            this.buttonCancel = new System.Windows.Forms.Button();
            this.buttonReply = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // labelDate
            // 
            this.labelDate.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold);
            this.labelDate.Location = new System.Drawing.Point(10, 30);
            this.labelDate.Name = "labelDate";
            this.labelDate.Size = new System.Drawing.Size(50, 20);
            this.labelDate.Text = "Date:";
            // 
            // labelSender
            // 
            this.labelSender.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold);
            this.labelSender.Location = new System.Drawing.Point(10, 10);
            this.labelSender.Name = "labelSender";
            this.labelSender.Size = new System.Drawing.Size(50, 20);
            this.labelSender.Text = "Sender:";
            // 
            // labelDateValue
            // 
            this.labelDateValue.Location = new System.Drawing.Point(70, 30);
            this.labelDateValue.Name = "labelDateValue";
            this.labelDateValue.Size = new System.Drawing.Size(100, 20);
            this.labelDateValue.Text = "label3";
            // 
            // labelSenderValue
            // 
            this.labelSenderValue.Location = new System.Drawing.Point(70, 10);
            this.labelSenderValue.Name = "labelSenderValue";
            this.labelSenderValue.Size = new System.Drawing.Size(100, 20);
            this.labelSenderValue.Text = "label4";
            // 
            // labelMessage
            // 
            this.labelMessage.Location = new System.Drawing.Point(10, 50);
            this.labelMessage.Name = "labelMessage";
            this.labelMessage.Size = new System.Drawing.Size(100, 20);
            this.labelMessage.Text = "label1";
            // 
            // buttonCancel
            // 
            this.buttonCancel.Location = new System.Drawing.Point(158, 210);
            this.buttonCancel.Name = "buttonCancel";
            this.buttonCancel.Size = new System.Drawing.Size(72, 20);
            this.buttonCancel.TabIndex = 0;
            this.buttonCancel.Click += new EventHandler(buttonCancelClick);
            this.buttonCancel.Text = "Cancel";
            // 
            // buttonReply
            // 
            this.buttonReply.Location = new System.Drawing.Point(10, 210);
            this.buttonReply.Name = "buttonReply";
            this.buttonReply.Size = new System.Drawing.Size(72, 20);
            this.buttonReply.TabIndex = 0;
            this.buttonReply.Click += new EventHandler(buttonReplyClick);
            this.buttonReply.Text = "Reply";
            // 
            // PanelMessageDetail
            // 
            this.Controls.Add(this.buttonCancel);
            this.Controls.Add(this.buttonReply);
            this.Controls.Add(this.labelDate);
            this.Controls.Add(this.labelDateValue);
            this.Controls.Add(this.labelMessage);
            this.Controls.Add(this.labelSender);
            this.Controls.Add(this.labelSenderValue);

            this.BackColor = System.Drawing.Color.LightGray;
            this.ResumeLayout(false);

        }

        public void uploadData(Message message)
        {
            this.message = message;

            this.labelSenderValue.Text = message.Sender.ScreenName;

            DateTime date = message.CreatedAt;
            if (DateTime.Now.Day == date.Day && DateTime.Now.Month == date.Month && DateTime.Now.Year == date.Year)
                this.labelDateValue.Text = "Today " + date.Hour + ":" + date.Minute;
            else
                this.labelDateValue.Text = date.Day + "/" + date.Month + "/" + date.Year;

            this.labelMessage.Text = message.Text;
        }

        private void buttonCancelClick(object sender, EventArgs args)
        {
            this.controller.performUserInput(TwitterClientController.MESSAGE_DETAILS_CANCEL_CLICK, null);
        }

        private void buttonReplyClick(object sender, EventArgs args)
        {
            TwitterClientEvent tEvent = new TwitterClientEvent();
            if (this.message.Sender.ScreenName.Equals(this.model.username))
                tEvent.paramList.Add(this.message.Recipient.ScreenName);
            else
                tEvent.paramList.Add(this.message.Sender.ScreenName);
            this.controller.performUserInput(TwitterClientController.MESSAGE_DETAILS_REPLY_CLICK, tEvent);
        }
    }
}
